package com.tedu.controller;

import com.tedu.entry.vo.EmpUpdateVO;
import com.tedu.service.EmpService;
import com.tedu.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Author：毕龙
 * Date: 2023/7/29 11:05
 */
@WebServlet("/emp/update")
public class EmpUpdateController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

       //1.处理请求
        //处理中文乱码
        request.setCharacterEncoding("utf-8");
        //获取请求的数据
        String name = request.getParameter("name");
        String id = request.getParameter("id");
        String salary = request.getParameter("salary");
        String age = request.getParameter("age");
        String birthday = request.getParameter("birthday");
        String deptId = request.getParameter("deptId");
        EmpUpdateVO vo = new EmpUpdateVO();
        vo.setId(id).setName(name).setSalary(salary).setAge(age).setBirthday(birthday).setDeptId(deptId);
        System.out.println(vo);

        //2. 调用业务逻辑
        EmpService service = new EmpServiceImpl();
        service.updateEmp(vo);

        //3. 跳转
        response.sendRedirect(request.getContextPath()+"/emp/findAll");


    }
}
